<template>
  <el-dialog
    title="设计师列表"
    :visible.sync="distributionVisible"
    :before-close="beforeClose"
    :close-on-click-modal="false"
    @open="open"
  >
    <el-table :data="DistributionList" height="450" v-if="type == 0">
      <el-table-column
        property="ad_name"
        label="姓名"
        align="center"
      ></el-table-column>
      <el-table-column
        property="nickname"
        label="职位"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button type="text" size="default" @click="onSelect(row.id)"
            >选中</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-table :data="applyforlist" height="450" v-else>
      <el-table-column
        property="ad_title"
        label="姓名"
        align="center"
      ></el-table-column>
      <el-table-column
        property="suit_title"
        label="套装名称"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button type="text" size="default" @click="onConsent(row.id,1)"
            >同意</el-button
          >
          <!-- <el-button type="text" size="default" @click="onConsent(row.id,2)"
            >拒绝</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
</template>

<script>
import { postApigetdesigner, postApibinding } from "@/api";
export default {
  props: {
    distributionVisible: {
      type: Boolean,
      default: false,
    },
    id: [String, Number],
    type: {
      type: [String, Number],
      default: 0,
    },
    identity: {
      type: [String, Number],
      default: 1,
    }
  },
  data() {
    return {
      DistributionList: [],
      applyforlist: [],
    };
  },
  activated() {},
  methods: {
    beforeClose() {
      this.$emit("close");
    },
    // 同意
    onConsent(id,type){
      let data = {
        id,
        type
      }
      postApiagree(data).then(res=>{
        if(type==0){
          this.$emit("postApigetsuit");
          this.$emit("close");
        }else{
          this.postApigetshensuit();
        }
      })
    },
    // 打开时的回调
    open() {
      if (this.type == 0) {
        this.postApigetdesigner();
      } else {
        this.postApigetshensuit();
      }
    },
    // 选中分配
    onSelect(uid) {
      let id = this.id;
      let data = {
        id,
        uid,
      };
      console.log("data", data);
      postApibinding(data)
        .then((res) => {
          this.$message.success("分配成功");
          this.$emit("postApigetsuit");
          this.$emit("close");
        })
        .catch((err) => {
          this.$message.warning(err.msg);
        });
    },
    // 申请列表
    postApigetshensuit() {
      postApigetshensuit(this.id).then((res) => {
        this.applyforlist = res.data;
      });
    },
    // 设计师列表
    postApigetdesigner() {
      let type = this.identity
      let data = {
        type
      }
      postApigetdesigner(data).then((res) => {
        console.log("设计师列表--->", res);
        this.DistributionList = res.data;
      });
    },
  },
};
</script>

<style>
</style>